<?php

namespace App\Controller;

use Hyperf\Contract\OnMessageInterface;
use Hyperf\Contract\OnCloseInterface;
use Hyperf\Contract\OnOpenInterface;
class WebSocketController implements onMessageInterface, OnCloseInterface, OnOpenInterface
{
    public function onMessage($server, $frame): void
    {
        $server->push($frame->fd, "收到信息 {$frame->data}");
    }

    public function onClose($server, int $fd, int $reactorId): void
    {
        echo "关闭了\n";
    }

    public function onOpen($server, $request): void
    {
        $server->push($request->fd,"连接成功");
    }
}